home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / init.d / pcscd < prev    next >
Encoding:
Text File  |  2012-03-31  |  4.2 KB  |  169 lines

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: pcscd
  4. # Required-Start:    $local_fs $remote_fs $syslog
  5. # Required-Stop:     $local_fs $remote_fs $syslog
  6. # Should-Start:      udev hal
  7. # Should-Stop:       udev hal
  8. # Default-Start:     2 3 4 5
  9. # Default-Stop:      0 1 6
  10. # Short-Description: Daemon to access a smart card using PC/SC
  11. # Description:       The PC/SC daemon is used to dynamically
  12. #                    allocate/deallocate reader drivers at runtime and manage
  13. #                    connections to the readers.
  14. ### END INIT INFO
  15.  
  16. # Authors: 
  17. #   Carlos Prados Bocos <cprados@debian.org>
  18. #   Ludovic Rousseau <rousseau@debian.org>
  19.  
  20. # Do NOT "set -e"
  21.  
  22. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  23. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  24. DESC="PCSC Lite resource manager"
  25. NAME=pcscd
  26. DAEMON=/usr/sbin/$NAME
  27. IPCDIR=/var/run/pcscd
  28. PIDFILE=$IPCDIR/$NAME.pid
  29. SCRIPTNAME=/etc/init.d/$NAME
  30.  
  31. # if you need to pass arguments to pcscd you should edit the file
  32. # /etc/default/pcscd and add a line 
  33. # DAEMON_ARGS="--your-option"
  34.  
  35. # Exit if the package is not installed
  36. [ -x "$DAEMON" ] || exit 0
  37.  
  38. # Read configuration variable file if it is present
  39. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  40.  
  41. # Load the VERBOSE setting and other rcS variables
  42. . /lib/init/vars.sh
  43.  
  44. # Do not start at boot using systemd but start using on-demand
  45. # http://ludovicrousseau.blogspot.com/2011/11/pcscd-auto-start-using-systemd.html
  46. if [ $1 = "start" -a -d /sys/fs/cgroup/systemd ]
  47. then
  48.     # Do not start from this script
  49.     exit 0
  50. fi
  51.  
  52. # Define LSB log_* functions.
  53. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  54. . /lib/lsb/init-functions
  55.  
  56. # get LANG variable (code from /etc/init.d/keymap.sh)
  57. ENV_FILE="none"
  58. [ -r /etc/environment ] && ENV_FILE="/etc/environment"
  59. [ -r /etc/default/locale ] && ENV_FILE="/etc/default/locale"
  60.  
  61. value=$(egrep "^[^#]*LANG=" $ENV_FILE | tail -n1 | cut -d= -f2)
  62. eval LANG=$value
  63.  
  64. #
  65. # Function that starts the daemon/service
  66. #
  67. do_start()
  68. {
  69.     # create $IPCDIR with correct access rights
  70.     if [ ! -d $IPCDIR ]
  71.     then
  72.         rm -rf $IPCDIR
  73.         mkdir $IPCDIR
  74.     fi
  75.     chgrp pcscd $IPCDIR
  76.     chmod 0775 $IPCDIR
  77.  
  78.     # Return
  79.     #   0 if daemon has been started
  80.     #   1 if daemon was already running
  81.     #   2 if daemon could not be started
  82.     start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  83.         || return 1
  84.     start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
  85.         $DAEMON_ARGS \
  86.         || return 2
  87.     # Add code here, if necessary, that waits for the process to be ready
  88.     # to handle requests from services started subsequently which depend
  89.     # on this one.  As a last resort, sleep for some time.
  90. }
  91.  
  92. #
  93. # Function that stops the daemon/service
  94. #
  95. do_stop()
  96. {
  97.     # Return
  98.     #   0 if daemon has been stopped
  99.     #   1 if daemon was already stopped
  100.     #   2 if daemon could not be stopped
  101.     #   other if a failure occurred
  102.     start-stop-daemon --stop --quiet --retry=3 --pidfile $PIDFILE --name $NAME
  103.     RETVAL="$?"
  104.     [ "$RETVAL" = 2 ] && return 2
  105. }
  106.  
  107. #
  108. # Function that sends a SIGHUP to the daemon/service
  109. #
  110. do_reload() {
  111.     #
  112.     # If the daemon can reload its configuration without
  113.     # restarting (for example, when it is sent a SIGHUP),
  114.     # then implement that here.
  115.     #
  116.     start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
  117.     return 0
  118. }
  119.  
  120. case "$1" in
  121.   start)
  122.     [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  123.     do_start
  124.     case "$?" in
  125.         0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  126.         2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  127.     esac
  128.     ;;
  129.   stop)
  130.     [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  131.     do_stop
  132.     case "$?" in
  133.         0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  134.         2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  135.     esac
  136.     ;;
  137.   status)
  138.       status_of_proc -p "$PIDFILE" "$DAEMON" "$NAME" && exit 0 || exit $?
  139.       ;;
  140.   restart|force-reload)
  141.     #
  142.     # If the "reload" option is implemented then remove the
  143.     # 'force-reload' alias
  144.     #
  145.     log_daemon_msg "Restarting $DESC" "$NAME"
  146.     do_stop
  147.     case "$?" in
  148.       0|1)
  149.         do_start
  150.         case "$?" in
  151.             0) log_end_msg 0 ;;
  152.             1) log_end_msg 1 ;; # Old process is still running
  153.             *) log_end_msg 1 ;; # Failed to start
  154.         esac
  155.         ;;
  156.       *)
  157.           # Failed to stop
  158.         log_end_msg 1
  159.         ;;
  160.     esac
  161.     ;;
  162.   *)
  163.     echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  164.     exit 3
  165.     ;;
  166. esac
  167.  
  168. :
  169.